<?
	$db = GetDefaultConnection();

	if ($oitem2!="Y")
	{
		$where = " and T_PRODUCT_DATE>='$sdate' and T_PRODUCT_DATE<='$edate' ";

		$queryarry = array(
			'JBNH_SEQ' => $jseq,
			'T_PRODUCT_ITEM1' => $item1,
			'T_PRODUCT_ITEM2' => $item2,
			'R_PRODUCT_GRADE1' => $ograde1,
			'R_PRODUCT_GRADE2' => $ograde2,
			'R_PRODUCT_STANDARD1' => $ostandard1,
			'R_PRODUCT_STANDARD2' => $ostandard2,
			'R_PRODUCT_WEIGHT1' => $oweight1,
			'R_PRODUCT_WEIGHT2' => $oweight2,
		);

		$query=makeWhereQry($queryarry);

		if ($query != "")
			$where .= " and ". $query;

		$sql = sprintf("SELECT R_PRODUCT_SEQ, R_PRODUCT_DATE, R_PRODUCT_WEIGHT2, R_PRODUCT_NUMBER, (R_PRODUCT_TOTAL-R_PRODUCT_LOSS) as R_PRODUCT_TOTAL "
						.", (select JBNH_NAME FROM TB_JBNH WHERE JBNH_SEQ=a.JBNH_SEQ) as JBNH_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.T_PRODUCT_ITEM1 AND CODE_CODE2=0) as ITEM1_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.T_PRODUCT_ITEM1 AND CODE_CODE2=a.T_PRODUCT_ITEM2) as ITEM2_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='B' AND CODE_CODE1=b.R_PRODUCT_GRADE1 AND CODE_CODE2=b.R_PRODUCT_GRADE2) as GRADE2_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='B' AND CODE_CODE1=b.R_PRODUCT_STANDARD1 AND CODE_CODE2=b.R_PRODUCT_STANDARD2) as STANDARD2_NAME "
						." FROM TB_PRODUCT_TEMP a inner join TB_PRODUCT_RESULT b on a.T_PRODUCT_SEQ=b.T_PRODUCT_SEQ where 1=1 %s order by a.T_PRODUCT_SEQ desc "
						, $where);
		$list = $db->queryList($sql)
?>
<?
		if ($list->getLength() == 0)
		{
?>
			<tr>
				<td colspan=10>등록된 목록이 없습니다.</td>
			</tr>
<?
		}
		else
		{
			$sum=0;
			while ($list->hasNext())
			{
				$row = & $list->next();
				$r_product_seq = $row->getString('R_PRODUCT_SEQ');
				$r_product_date = $row->getString('R_PRODUCT_DATE');
				$jbnh_name = $row->getString('JBNH_NAME');
				$item1_name = $row->getString('ITEM1_NAME');
				$item2_name = $row->getString('ITEM2_NAME');
				$r_product_weight2 = $row->getNumber('R_PRODUCT_WEIGHT2');
				$grade2_name = $row->getString('GRADE2_NAME');
				$standard2_name = $row->getString('STANDARD2_NAME');
				$r_product_number = $row->getNumber('R_PRODUCT_NUMBER');
				$r_product_total = $row->getNumber('R_PRODUCT_TOTAL');
				$sum += $r_product_total;
?>
				<tr>
                	<td><?=$r_product_date?></td>
                    <td><?=$jbnh_name?></td>
					<td><?=$item1_name?></td>
                    <td><?=$item2_name?></td>
                    <td><?=$grade2_name?></td>
                    <td><?=$standard2_name?></td>
                    <td><?=$r_product_weight2?>kg</td>
					<td><?=$r_product_number?>개</td>
                    <td><?=$r_product_total?>kg</td>
					<td class="start"><a href="#" onClick="doPrint('print_sunbyul.html?seq=<?=$r_product_seq?>', 1000, 600);"><p class="sort_print"><span>선별확인증 인쇄</span></p></a></td>
                </tr>
<?
			}
		}
	}
	else
	{
		$where = " and PRODUCT_DATE>='$sdate' and PRODUCT_DATE<='$edate' ";

		$queryarry = array(
			'JBNH_SEQ' => $jseq,
			'PRODUCT_ITEM1' => $item1,
			'PRODUCT_ITEM2' => $item2,
			'PRODUCT_GRADE1' => $ograde1,
			'PRODUCT_GRADE2' => $ograde2,
			'PRODUCT_STANDARD1' => $ostandard1,
			'PRODUCT_STANDARD2' => $ostandard2,
			'PRODUCT_WEIGHT1' => $oweight1,
			'PRODUCT_WEIGHT2' => $oweight2,
		);

		$query=makeWhereQry($queryarry);

		if ($query != "")
			$where .= " and ". $query;

		$sql = sprintf("SELECT PRODUCT_DATE, PRODUCT_WEIGHT2, PRODUCT_NUMBER, PRODUCT_TOTAL "
						.", (select JBNH_NAME FROM TB_JBNH WHERE JBNH_SEQ=a.JBNH_SEQ) as JBNH_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.PRODUCT_ITEM1 AND CODE_CODE2=0) as ITEM1_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.PRODUCT_ITEM1 AND CODE_CODE2=a.PRODUCT_ITEM2) as ITEM2_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='B' AND CODE_CODE1=a.PRODUCT_GRADE1 AND CODE_CODE2=a.PRODUCT_GRADE2) as GRADE2_NAME "
						.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='B' AND CODE_CODE1=a.PRODUCT_STANDARD1 AND CODE_CODE2=a.PRODUCT_STANDARD2) as STANDARD2_NAME "
						." FROM TB_PRODUCT a where 1=1 %s order by PRODUCT_SEQ desc "
						, $where);
		$list = $db->queryList($sql)
?>
<?
		if ($list->getLength() == 0)
		{
?>
			<tr>
				<td colspan=10>등록된 목록이 없습니다.</td>
			</tr>
<?
		}
		else
		{
			$sum=0;
			while ($list->hasNext())
			{
				$row = & $list->next();
				$product_date = $row->getString('PRODUCT_DATE');
				$jbnh_name = $row->getString('JBNH_NAME');
				$item1_name = $row->getString('ITEM1_NAME');
				$item2_name = $row->getString('ITEM2_NAME');
				$product_weight2 = $row->getNumber('PRODUCT_WEIGHT2');
				$grade2_name = $row->getString('GRADE2_NAME');
				$standard2_name = $row->getString('STANDARD2_NAME');
				$product_number = $row->getNumber('PRODUCT_WEIGHT2');
				$product_total = $row->getNumber('PRODUCT_TOTAL');
				$sum += $product_total;
?>
				<tr>
                	<td><?=$product_date?></td>
                    <td><?=$jbnh_name?></td>
					<td><?=$item1_name?></td>
                    <td><?=$item2_name?></td>
                    <td><?=$grade2_name?></td>
                    <td><?=$standard2_name?></td>
                    <td><?=$product_weight2?>kg</td>
					<td><?=$product_number?>개</td>
                    <td><?=$product_total?>kg</td>
					<td>-</td>
                </tr>
<?
			}
		}
	}
?>